package com.hyy.backend.controller;


import com.hyy.backend.common.Result;
import com.hyy.backend.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/api/post")
public class PostController {

    @Autowired
    private PostService postService;

    @GetMapping("/{id}")
    public Result<Map<String, Object>> getPostDetail(@PathVariable Integer id) {
        return postService.getPostDetail(id);
    }
    @GetMapping("/all")
    public Result<List<Map<String, Object>>> getAllPosts() {
        return postService.getAllPosts();
    }
    @PostMapping("/{id}/like")
    public Result<Map<String, Object>> likePost(@PathVariable Integer id, @RequestParam Integer userId) {
        return postService.likePost(id, userId);
    }
    @PostMapping("/{id}/favorite")
    public Result<Map<String, Object>> favoritePost(@PathVariable Integer id, @RequestParam Integer userId) {
        return postService.favoritePost(id, userId);
    }
    @DeleteMapping("/{id}")
    public Result<String> deletePost(@PathVariable Integer id) {
        return postService.deletePostAndRelatedData(id);
    }




}